package it.polimi.registration.business.security.entity;

import it.polimi.registration.business.weather.ForecastFactory;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
public class Forecast implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Calendar date;
	private int confidence;
	private WeatherType type;
	
	@OneToOne
	private Event owner;
	
	public Forecast() {
		
	}
	
	public Forecast(Event owner) {
		this();
		this.owner = owner;
	}
	
	public Forecast(Event owner, Calendar date2, String location) {
		this(owner);
	}

	public int getConfidence() {
		return confidence;
	}
	
	public Calendar getDate() {
		return date;
	}
	
	public int getId() {
		return id;
	}
	
	public Event getOwner() {
		return owner;
	}
	
	public WeatherType getType() {
		return type;
	}
	
	public String getTypeString() {
		if(type == WeatherType.Bad)
			return "bad";
		return "sunny";
	}
	
	public void setType(WeatherType type) {
		this.type = type;
	}
	
	public void setConfidence(int confidence) {
		this.confidence = confidence;
	}
	
	public void setDate(Calendar date) {
		this.date = date;
	}

	public void update() throws Exception {
		new ForecastFactory(this);
	}
}
